//
//  RepairByChooseDateViewController.m
//  GetPowerDBO
//
//  Created by 周博 on 2017/7/25.
//  Copyright © 2017年 BogoZhou. All rights reserved.
//

#import "RepairByChooseDateViewController.h"
#import "GTLCalendarView.h"

@interface RepairByChooseDateViewController ()<GTLCalendarViewDataSource, GTLCalendarViewDelegate>
{
    NSString *_startDate;
    NSString *_endDate;
}
@end

@implementation RepairByChooseDateViewController

#pragma mark - GTLCalendarViewDataSource

- (NSDate *)minimumDateForGTLCalendar {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd";
    NSString *minimumD = @"2017-06-01";

    return [dateFormatter dateFromString:minimumD];
}

- (NSDate *)maximumDateForGTLCalendar {
    return [NSDate new];
}

- (NSDate *)defaultSelectFromDate {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd";
    
//    NSString *toDate ;
//    if ([BGFunctionHelper isNULLOfString:_start]) {
//        toDate = [BGDateHelper seeDayAroundToday:-8][0];
//        
//        NSString *startLongLong = [BGDateHelper getTimeStempByString:toDate havehh:NO];
//        NSString *beginLongLong = [BGDateHelper getTimeStempByString:_beginDate havehh:NO];
//        if (beginLongLong.longLongValue > startLongLong.longLongValue) {
//            toDate = _beginDate;
//        }
//        
//    }else{
//        toDate = _start;
//    }
    
    return [dateFormatter dateFromString:_start];
}

- (NSDate *)defaultSelectToDate {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd";
//    NSString *toDate ;
//    if ([BGFunctionHelper isNULLOfString:_end]) {
//        toDate = [BGDateHelper seeDayAroundToday:-1][0];
//    }else{
//        toDate = _end;
//    }
    return [dateFormatter dateFromString:_end];
}

#pragma mark - GTLCalendarViewDelegate

- (NSInteger)rangeDaysForGTLCalendar {
    return 30 * 6;
}

- (void)selectNSStringFromDate:(NSString *)fromDate toDate:(NSString *)toDate {
    NSLog(@"fromDate: %@, toDate: %@", fromDate, toDate);
    _startDate = fromDate;
    _endDate = toDate;
}

#pragma mark - private instance method

#pragma mark * init values

- (void)setupGTLCalendarViews {
    CGRect frame = CGRectMake(0, 0, _viewContent.sizeWidth, _viewContent.sizeHeight);
    
    GTLCalendarView *gtlCalendarView = [[GTLCalendarView alloc] initWithFrame:frame];
    gtlCalendarView.dataSource = self;
    gtlCalendarView.delegate = self;
    gtlCalendarView.typeValueRepair = @"1";
    [_viewContent addSubview:gtlCalendarView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupGTLCalendarViews];

}





#pragma mark - 点击时间
//返回
- (IBAction)backButtonClick:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

//确定按钮
- (IBAction)sureButtonClick:(UIButton *)sender {
    if ([BGFunctionHelper isNULLOfString:_startDate]) {
        _startDate = _start;
    }
    [_delegate getChooseDate:_startDate];
    [self dismissViewControllerAnimated:YES completion:nil];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
